home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT25.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.6 KB  |  147 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 25                         
  5.                                           
  6.  Good practice for understanding the movement and animation commands.        
  7.  See if you can guess what each move will do before you run this program.    
  8.  It will help you understand the format for the movements.                   
  9.  Press 'Q' to quit.                                                          
  10.                                           
  11.  *** PROJECT ***                                                             
  12.  This program requires the WSPR_WC.LIB and the WGT5_WC.LIB to be linked.     
  13.                                           
  14.  *** DATA FILES ***                                                          
  15.  Make sure that you have MOUSE.SPR in your executable directory.             
  16.                                WATCOM C++ VERSION 
  17. ==============================================================================
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include <conio.h>
  23. #include <stdlib.h>
  24. #include <malloc.h>
  25. #include <wgt5.h>
  26. #include <wgtspr.h>
  27.  
  28. block sprites[100];                    /* Pointers to sprites */
  29. short quit;                             /* If quit !=0, program quits */
  30. short sprite_toggle = 0;                /* Toggles movement and animation */
  31. char c;                                 /* Input from keyboard - q quits */
  32. color palette[256];                     /* Our palette */
  33.  
  34. void looper (void);      /* a routine which controls the sprites */
  35.  
  36. void main (void)
  37. {
  38.   short i;                                /* Loop counter */
  39.   short oldmode;                          /* Stores previous video mode */
  40.   
  41.   if ( !vgadetected() )
  42.   {
  43.     printf("Error - VGA card required for any WGT program.\n");
  44.     exit (0);
  45.   }
  46.  
  47.   printf ("WGT Example #25\n\n");
  48.   printf ("Another sprite movement and animation demo......\n");
  49.   printf ("Press Q to end the program. Any other key toggles the movement and\n");
  50.   printf ("animation status of the sprites.\n");
  51.   printf ("\n\nPress any key to continue.\n");
  52.   getch ();
  53.  
  54.   oldmode = wgetmode ();
  55.   vga256 ();
  56.   wloadsprites (palette, "mouse.spr", sprites, 0, 99);    /* load them */
  57.   wsetpalette (0, 255, palette);
  58.   initialize_sprites (sprites);                     /* initialize them */
  59.   maxsprite = 2;                                    /* number of sprites on */
  60.   
  61.   minit ();
  62.  
  63.   for (i = 0; i < 200; i++)                 /* draw a background */
  64.   {
  65.    wsetcolor (i);
  66.    wfline (0, i, 159, i);
  67.    wfline (160, 199 - i, 319, 199 - i);
  68.   }
  69.  
  70.   wcopyscreen (0, 0, 319, 199, NULL, 0, 0, spritescreen);
  71.   wcopyscreen (0, 0, 319, 199, NULL, 0, 0, backgroundscreen);
  72.   /* when using sprites, whatever is on the visual page must be on
  73.      spritescreen and background too! */
  74.  
  75.   spriteon (0, 0, 0, 1);
  76.   animate (0, "(1,30)(2,30)(3,30)(4,30)(3,30)(2,30)R");
  77.   movex (0, "(2,150,0)(0,90,0)(-2,150,0)(0,90,0)R");
  78.   movey (0, "(0,150,0)(2,90,0)(0,150,0)(-2,90,0)R");
  79.  
  80.   spriteon (1, 160, 0, 1);
  81.   animate (1, "(1,30)(2,30)(3,30)(4,30)R");
  82.   movex (1, "(-1,150,0)(1,300,0)(-1,150,0)R");
  83.   movey (1, "(1,180,0)(-1,180,0)R");
  84.  
  85.   spriteon (2, 0, 100, 1);
  86.   animate (2, "(1,30)(4,30)R");
  87.   movex (2, "(1,300,1)(-300,1,0)R");
  88.   movey (2, "(0,1,0)");                   /* must set a y move since
  89.                        I turn it on below even
  90.                        if it doens't do anything */
  91.   for (i = 0; i < 3; i++)
  92.   {
  93.    animon (i);
  94.    movexon (i);
  95.    moveyon (i);
  96.   }
  97.  
  98.   do {
  99.     looper ();
  100.   } while (!quit);
  101.  
  102.   spriteoff (0);                 /* turn off sprite */
  103.   spriteoff (1);                 /* turn off sprite */
  104.   spriteoff (2);                 /* turn off sprite */
  105.   /* To be safe, turn off all sprites before ending program.
  106.      This will free any memory used from them. */
  107.   deinitialize_sprites();
  108.   mdeinit ();                   /* Deinitialize the mouse handler */
  109.  
  110.   wfreesprites (sprites, 0, 99);         /* free memory */
  111.   wsetmode (oldmode);
  112. }
  113.  
  114.  
  115. void looper(void)
  116. {
  117.   short i;
  118.  
  119.   erase_sprites ();                /* clear the sprites */
  120.   if (kbhit ())
  121.    {
  122.     c = toupper (getch ());
  123.     if (c == 'Q')
  124.     quit = 1;
  125.     
  126.     sprite_toggle = !sprite_toggle;
  127.     
  128.     if (sprite_toggle)
  129.       for (i = 0; i < 3; i++)
  130.        {
  131.     movexoff (i);
  132.     moveyoff (i);
  133.     animoff (i);
  134.        }
  135.     else
  136.       for (i = 0; i < 3; i++)
  137.        {
  138.     movexon (i);
  139.     moveyon (i);
  140.     animon (i);
  141.        }
  142.    }
  143.   wretrace ();
  144.   draw_sprites (1);            /* draw them back on */
  145.   /* This loop is required to update sprite positions */
  146. }
  147.